package com.example.common.config;

import com.example.common.properties.PathProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.List;

@Configuration
public class WebConfig implements  WebMvcConfigurer {

    @Autowired
    private PathProperties pathProperties;

    @Resource
    private JwtInterceptor jwtInterceptor;

    // 加自定义拦截器JwtInterceptor，设置拦截规则
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> ignoreUrl = pathProperties.getIgnoreUrl();
        registry.addInterceptor(jwtInterceptor).addPathPatterns("/**")
                .excludePathPatterns(ignoreUrl);
    }
}